cmake_minimum_required(VERSION 3.20)

project(CMake_Custom_Command)

# 添加自定义命令
add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/data.h
    COMMAND MakeData > ${CMAKE_CURRENT_BINARY_DIR}/data.h
    # 先构建依赖再执行命令
    DEPENDS MakeData
)
add_executable(MakeData makedata.cpp)

# 添加了data.h 自定义命令才会执行
add_executable(custom_command main.cpp data.h)
target_include_directories(custom_command PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
